/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_TCP_CLIENT_H
#define MK_TCP_CLIENT_H
#include "MkSocket/MkSocket.h"
#include "MkUtil/MkRwLock.h"
#include <atomic>

class CMkTcpClient;
typedef MkFunction<void(CMkTcpClient* pClient)> MkEventRemovedCallback;
typedef MkFunction<void()> MkConnectedCallback;
class MkApi CMkTcpClient : public CMkSocket
{
public:
    CMkTcpClient(CMkEvent* pEvent, CMkTimer* pTimer, const MkEventRemovedCallback& RemovedCb);
    ~CMkTcpClient();
    virtual Uint32 ConnectServer(const MkString& Ip, Uint16 Port, const MkConnectedCallback& ConnectCb);
    void DeleteLater();
protected:
    virtual Uint32 OnEventRemoved() override;
    virtual Uint32 OnConnect() override;
private:
    MkEventRemovedCallback m_RemovedCb;
    MkConnectedCallback     m_ConnectedCb;
};

#endif
